/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sbbs.flux.lambda;

import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

/**
 * lambda的惰性求值
 *
 * @author 晓风轻
 */
public class LogDemo {

    private static final Logger logger = Logger.getLogger(LogDemo.class.getName());

    @Override
    public String toString() {
        System.out.println("这个方法执行了, 耗时1秒钟");
        try {
            TimeUnit.SECONDS.sleep(1);
        } catch (InterruptedException e) {
        }

        return "LogDemo";
    }

    public void test() {
        // 如果不加判断直接打印, 会有额外多余的开销, 就算最终日志并没有打印
        logger.info("打印一些日志:" + this.toString());
        logger.fine(() -> "打印一些日志:" + this);//如果执行，有点像下面代码
//        String msg = "打印一些日志:" + this
//logger.fine(msg);

    }

    public static void main(String[] args) {
        LogDemo demo = new LogDemo();
        demo.test();
    }
}
